package com.xinyan.vo;

import lombok.Data;

import java.io.Serializable;

@Data
public class R<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> R result(Integer code, String msg, T data) {
        return new R(code, msg, data);
    }

    public static R ok() {
        return result(200, "success", null);
    }

    public static <T> R ok(T data) {
        return result(200, "success", data);
    }

    public static R fail() {
        return result(400, "fail", null);

    }

    public static R fail(Integer code) {
        return result(code, "fail", null);
    }
    public static R fail(String msg) {
        return result(400, msg, null);
    }

    public static <T> R fail(T data) {
        return result(400, "fail", data);
    }

    public static <T> R fail(Integer code, T data) {
        return result(code, "fail", data);
    }

    public static R fail(Integer code, String msg) {
        return result(code, msg, null);
    }

    public static <T> R fail(Integer code, String msg, T data) {
        return result(code, msg, data);
    }
}
